class ServiceMapper:
    """端口服务映射器"""

    # 增强的端口服务映射表
    PORT_SERVICE_MAP = {
        # Web服务
        80: "HTTP (Web服务器)",
        443: "HTTPS (安全Web服务器)",
        8080: "HTTP-Alt (备用Web服务器)",
        8443: "HTTPS-Alt (备用安全Web服务器)",
        3000: "Node.js开发服务器/Grafana",
        3001: "React开发服务器",
        4200: "Angular开发服务器",
        5000: "Flask开发服务器",
        8000: "Django开发服务器",
        8888: "Jupyter Notebook",
        9000: "SonarQube",
        # 数据库服务
        3306: "MySQL数据库",
        5432: "PostgreSQL数据库",
        1433: "SQL Server数据库",
        1521: "Oracle数据库",
        27017: "MongoDB数据库",
        6379: "Redis缓存",
        11211: "Memcached缓存",
        9200: "Elasticsearch",
        5984: "CouchDB",
        # 消息队列
        5672: "RabbitMQ",
        9092: "Apache Kafka",
        61616: "ActiveMQ",
        # 远程访问
        22: "SSH (安全Shell)/SFTP (安全文件传输)",
        23: "Telnet",
        3389: "RDP (远程桌面)",
        5900: "VNC远程桌面",
        # 文件传输
        21: "FTP (文件传输)",
        990: "FTPS (安全FTP)",
        # 邮件服务
        25: "SMTP (邮件发送)",
        110: "POP3 (邮件接收)",
        143: "IMAP (邮件接收)",
        993: "IMAPS (安全IMAP)",
        995: "POP3S (安全POP3)",
        # DNS和网络
        53: "DNS (域名解析)",
        67: "DHCP服务器",
        68: "DHCP客户端",
        # 开发工具
        8086: "InfluxDB",
        9090: "Prometheus",
        15672: "RabbitMQ管理界面",
        # 容器和虚拟化
        2375: "Docker API (非安全)",
        2376: "Docker API (安全)",
        8001: "Kubernetes API",
        # 游戏和娱乐
        25565: "Minecraft服务器",
        27015: "Steam游戏服务器",
        # Windows服务
        135: "RPC (远程过程调用)",
        139: "NetBIOS会话服务",
        445: "SMB (文件共享)",
        # 其他常用服务
        161: "SNMP (网络管理)",
        389: "LDAP (目录服务)",
        636: "LDAPS (安全LDAP)",
        1080: "SOCKS代理",
        3128: "Squid代理",
    }

    @classmethod
    def get_service_name(cls, port: int) -> str:
        """获取端口对应的服务名称"""
        # 直接映射
        if port in cls.PORT_SERVICE_MAP:
            return cls.PORT_SERVICE_MAP[port]

        # 智能分类
        if 1000 <= port <= 1024:
            return "系统保留端口"
        elif 8000 <= port <= 8999:
            return "Web开发服务器"
        elif 9000 <= port <= 9999:
            return "应用服务器"
        elif 3000 <= port <= 3999:
            return "开发服务器"
        elif 5000 <= port <= 5999:
            return "应用程序端口"
        elif port >= 49152:
            return "动态/私有端口"
        else:
            return "未知服务"
